{extend name="public/base"/}
{block name="style"}
<link href="__PUBLIC__/ieasy/css/classify.css?v=2.1.49" rel="stylesheet" type="text/css">
<style type="text/css">
	.s_main{
		overflow: hidden;
		background-color: #fff;
	}
	.s_img{
		overflow: hidden;
		margin: .5rem auto .2rem;
		width: 1.43rem;
		height: 1.43rem;
	}
	.s_img img{
		display: block;
		width: 100%;
		height: 100%;
	}
	.s_main h1{
		height: .36rem;
		color: #0a347e;
		font-size: .21rem;
		text-align: center;
		line-height: .36rem;
	}
	.s_main strong{
		display: block;
		overflow: hidden;
		height: .36rem;
		font-size: .15rem;
		color: #5e6a94;
		text-align: center;
		line-height: .36rem;
	}
	.s_main strong span{
		display: inline;
		font-size: .15rem;
		color: #f63566;
	}
	.content_null_but_box a{
		height: .36rem;
		font-size: .16rem;
		line-height: .36rem;
	}
	.s_main .s_main_over{
		background-color: #f63566;
	}
	
	.s_fixed_box{
		display: none;
		padding-top: 2.6rem;
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		z-index: 1000;
		background: rgba(0,0,0,.8) url(__PUBLIC__/ieasy/img/icon_28.png?v=2.1.49) no-repeat center 1.46rem;
		background-size: 1.87rem 1.17rem;
	}
	.s_fixed_box strong,
	.s_fixed_box em{
		display: block;
		text-align: center;
		font-weight: normal;
	}
	.s_fixed_box strong{
		font-size: .24rem;
		color: #ff4b4b;
		line-height: .32rem;
	}
	.s_fixed_box em{
		font-size: .15rem;
		color: #77a4ff;
		line-height: .24rem;
	}
	.s_fixed_box em span{
		display: inline;
		color: #ff4b4b;
	}
	.s_fixed_box a{
		margin: .4rem auto 0;
		display: block;
		width: 2.1rem;
		height: .36rem;
		border: 1px solid #fff;
		border-radius: .36rem;
		font-size: .16rem;
		color: #fff;
		text-align: center;
		line-height: .36rem;
	}
</style>
{/block}
{block name="body"}
<div id="console_main"></div>
<div class="head_tit_box">
	<a href="javascript:;" class="head_return_page_but"></a>
		<div class="head_menu_but_box">
		<a href="javascript:;" class="head_menu_but"></a>
	</div>
		<h1>签到</h1>
</div>
<!--导航-->
{block name="include"}{include file="public:dropnav" /}{/block}

<div class="body_sytle">

	<div class="s_main">
		<div class="s_img"><img src="__PUBLIC__/ieasy/img/icon_27.png?v=2.1.49" /></div>
		<h1>签到送礼</h1>
		<strong>每日签到可获得<span>{$qbegold}书币</span>奖励</strong>
		<div class="content_null_but_box">

			<p class="weui_btn_area">
			{if $qiandao}
				<a href='/personal/history' class='weui_btn weui_btn_primary'>今日已签到,继续阅读</a>
			{else}
				<a href='JavaScript:checkin();' class='weui_btn weui_btn_primary'>立即签到</a>
			{/if} 
			</p>

		</div>
	</div>	
	
</div>

{/block}
{block name="script"}
<script type="text/javascript" src="__PUBLIC__/ieasy/js/zepto.min.js?v=2.1.49"></script>
<script type="text/javascript" src="__PUBLIC__/ieasy/js/zepto.cookie.min.js?v=2.1.49"></script>

<!-- 这是zepto插件 -->

<script type="text/javascript" src="__PUBLIC__/ieasy/js/common.js?v=2.1.49"></script>


<link rel="stylesheet" href="__PUBLIC__/ieasy/css/front.css" />
<link rel="stylesheet" href="__PUBLIC__/ieasy/css/vendor.css" />
<script src="__PUBLIC__/ieasy/js/vendor.js"></script>
<script src="__PUBLIC__/ieasy/js/app.js"></script>

<script type="text/javascript">
    var qiandao  = '{$qiandao|default=0}';
	var qbegold = {$qbegold};
	var expire = {:config('sign_expire')};

	$(function(){
		if (qiandao==1)
		{
			$('.weui_btn_primary').html('今日已签到,继续阅读')
		}
	})

    function checkin() {
            
        var strToday = getTodayString();
        var lastCheckinDate = window.localStorage.getItem('last_checkin_date');
		if (lastCheckinDate == strToday&&qiandao==1) {
			$.modal({
				title: '今天签到过啦',
				text: '<p>每日首次阅读, 赠送 <span style="color:orangered">'+qbegold+'</span> 书币</p>' +
				'<p style="margin-top:10px">请明日继续签到哦</p><p>签到赠送书币有效期为'+expire+'天</p>',
				buttons: [
					{text: '我知道啦',
					onClick: function () {
					  window.onpageshow = function (e) {
						if (e.persisted) {
						  location.reload();
						}
					  };

					  location.assign('/personal/info');
					}
					}
				]
			});
			return false;
		}
            $.ajax({
                url: '/personal/signin/',
                type: 'POST',
                dataType:'json',
                data: {usecenter: 1}
            })
                .then(function (result) {
					setCheckedIn();
                    $.modal({
                        title: '签到成功',
                        text: '<p>每日首次阅读, 赠送 <span style="color:orangered"> '+qbegold+'</span> 书币</p>' +
                        '<p style="margin-top:10px">请明日继续签到哦</p><p>签到赠送书币有效期为'+expire+'天</p>',
                        buttons: [
                            {text: '我知道啦',
								onClick: function () {
								  window.onpageshow = function (e) {
									if (e.persisted) {
									  location.reload();
									}
								  };

								  location.assign('/personal/info');
								}
							}
                        ]
                    })
                })
                .fail(function (xhr) {
                    var result = JSON.parse(xhr.responseText);
                    // 如果是未关注用户, 第一天无需自动签到, 标记为已签到,以减少后续 API 请求
                    // 如果是重复签到, 说明用户可能是在新设备访问, 补充标记//{{{md5code}}}
                    if (result.code === 'not_subscribed' || result.code === 'already_checked_in') {
                        //setCheckedIn();
                        $.modal({
                        title: '关注后签到才送积分哦!',
                        text: '<p>每日首次阅读, 赠送 <span style="color:orangered">50</span> 书币</p>' +
                        '<p style="margin-top:10px">请明日继续签到哦</p>',
                        buttons: [
                            {text: '我知道啦',handler:function(){location.href = '/personal/info';}}
                        ]
                    })
                    }
                });
        }
        function getTodayString() {
            var date = new Date();
            return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
        }

        function setCheckedIn() {
            window.localStorage.setItem('last_checkin_date', getTodayString());
        }
</script>
{/block}